# Contributor: Jason Qiu <jasonwqiu@gmail.com>

_realname=streamlink
pkgbase=mingw-w64-python-${_realname}
pkgver=5.5.1
pkgrel=2
pkgdesc="A CLI utility that extracts streams from various services and pipes them into a video player of choice."
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clangarm64' 'clang32')
url="https://github.com/streamlink/streamlink"
license=('spdx:BSD-2-Clause')
depends=("${MINGW_PACKAGE_PREFIX}-python"-{pycryptodome,isodate,pycountry,requests,pysocks,websocket-client,charset-normalizer})
makedepends=("${MINGW_PACKAGE_PREFIX}-python-"{build,installer,setuptools,versioningit,wheel})
checkdepends=("${MINGW_PACKAGE_PREFIX}-python-"{freezegun,pytest,pytest-asyncio,requests-mock})
optdepends=("${MINGW_PACKAGE_PREFIX}-ffmpeg: Required to play streams that are made up of separate audio and video streams, eg. YouTube 1080p+")
options=('!strip')
source=("${_realname}-${pkgver}.tar.gz::https://github.com/streamlink/streamlink/releases/download/${pkgver}/${_realname}-${pkgver}.tar.gz")
sha256sums=('b2b4fe8d6436dbe7bcec78de2d4bb780156388561435b61a1963156e9fc5fbd0')

prepare() {
  cp -r "${_realname}-${pkgver}" "python-build-${MSYSTEM}"

  # Set version for setuptools_scm
  export SETUPTOOLS_SCM_PRETEND_VERSION=${pkgver}
}

build() {
  cd "${srcdir}/python-build-${MSYSTEM}"
  ${MINGW_PREFIX}/bin/python -m build --wheel --skip-dependency-check --no-isolation
}

package() {
  cd "${srcdir}/python-build-${MSYSTEM}"
  MSYS2_ARG_CONV_EXCL="--prefix=" \
    ${MINGW_PREFIX}/bin/python -m installer --prefix=${MINGW_PREFIX} \
    --destdir="${pkgdir}" dist/*.whl

  install -Dm644 LICENSE ${pkgdir}${MINGW_PREFIX}/share/licenses/python-${_realname}/LICENSE
}
